package dse.messages.multiversion;

import java.util.*;

import dse.*;
import dse.messages.*;

public class VersionResponseMessageHandler extends MessageSender implements
		MessageHandler {
	private TreeSet<Version> versions;
	private VersionReader reader;
	
	public VersionResponseMessageHandler (
			Experiment experiment, 
			TreeSet<Version> versions,
			VersionReader reader
			)
	{
		super(experiment);
		
		this.versions = versions;
		this.reader = reader;
	}

	
	@Override
	public boolean acceptMessage(Message message) {
		// TODO Auto-generated method stub
		return true;
	}

	@Override
	public void messageInterupted(ExperimentRecorder recorder, Message message,
			double timeLeft) {
		// TODO Auto-generated method stub
		recorder.debug(this, "msgIntrpt: " + message, timeLeft);
		reader.readVersion(recorder, null, timeLeft, message.from());
	}

	@Override
	public void messageReceived(ExperimentRecorder recorder, Message message,
			double timeLeft) {
		// TODO Auto-generated method stub
		recorder.debug(this, "msgRcvd: " + message, timeLeft);
		if (message.messageType() != MessageType.VersionResponse) {
			recorder.warn(
					"VersionResponseMessageHandler recieved " + 
					message.messageType() + " message."
					);
			return;
		}
		
		reader.readVersion(recorder, versions, timeLeft, message.from());
	}
}
